import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';

// 路由
import { Router } from './config/router.js'
// 工具类
import { getPath, cookie } from './utils/utils.js';
// 公用方法
// import { setCookie } from './common/common.js';
// 示例模块
import New from './page/new/New.js';
// 评论模块
import Comment from './page/comment/Comment.js';
// 公用方法
// import { 
// 	// 获取渠道Id
// 	getClientId,
// 	// 存cookie
// 	setCookie
// } from './common/common.js';

class Client extends Component {

	componentWillMount() {
		console.log(this)
		// 根据client参数，获取clientId，存储cookie
		// name, value, domain, path, expires
		cookie.set('clientId', this.props.match.params.clientId, '', '/', 10 *365 * 24);

		// 自动跳转(如果当前路径与 client 容器路径相同的场合)
		if (this.props.location.pathname === getPath(Router.client.path)) {
			// 自动跳转
			this.props.history.push({ 
				pathname: getPath(Router.client.comment.product.path)
			});
		}

	}
	componentDidMount() {
	}
	componentWillReceiveProps(newProps) {
	}
	// render 调用前调用
	shouldComponentUpdate(newProps, newState) {
		return true;
	}
	componentWillUpdate(nextProps, nextState) {}
	componentDidUpdate(prevProps, prevState) {}
	componentWillUnmount() {}

	render() {
		return (
			<div className="Client">
				<Switch>
					<Route path={ Router.client.new.path } component={ New }/>
					<Route path={ Router.client.comment.path } component={ Comment }/>
				</Switch>
			</div>
		);
	}
}

export default Client;
